/*******************************************************************************
 * Copyright (c) 2002 Boris Pruessmann and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Common Public License v0.5
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v05.html
 * 
 * Contributors:
 *    Boris Pruessmann - Initial implementation.
 ******************************************************************************/
package net.sourceforge.perforce.ui.dialogs;

import net.sourceforge.perforce.ui.internal.Policy;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;

/**
  * @version $Revision: 202 $
  * @author  <a href="mailto:bpruessmann@users.sourceforge.net">Boris Pruessmann</a>
  */
final class DialogUtils 
{
	// ------------------------------------------------------------------------ Private Constructors
	
	/** Constructor for DialogUtils. */
	private DialogUtils()
	{
	}
	
	// ----------------------------------------------------------------------- Public Static Methods
	
	/** Calle to create a checkbox button.
	  *
	  * @param parent the parent composite.
	  * @param text the button's text.
	  * @return the new Button. 
	  */
	public static Button createCheckButton(Composite parent, String text)
	{
		// ==( PRE-CONDITION )======================================================================
		Policy.assertNotNull(parent);
		Policy.assertNotNull(text);
		// ==( PRE-CONDITION )======================================================================
		
		Button result = new Button(parent, SWT.CHECK);
		result.setText(text);
		
		return result;
	}	
	
	/** Called to create a new combo within the given parent. 
	  * 
	  * @param parent the parent composite.
	  * @param widthHint hint fot the combo's width.
	  * @return the created Combo.  
	  */
	public static Combo createCombo(Composite parent, int widthHint)
	{
		// ==( PRE-CONDITION )======================================================================
		Policy.assertNotNull(parent);
		// ==( PRE-CONDITION )======================================================================
		
		Combo result = new Combo(parent, SWT.READ_ONLY);
		GridData data = new GridData(GridData.FILL_HORIZONTAL);
		data.widthHint = widthHint;
		result.setLayoutData(data);
		
		return result;
	}

	/** Creates a new composite within the specified parent, having <code>numColumns</code> columns.
	  *
	  * @param parent the parent of the composite.
	  * @param numColumns number of columns.
	  * @return the new Composite. 
	  */	
	public static Composite createComposite(Composite parent, int numColumns)
	{
		// ==( PRE-CONDITION )======================================================================
		Policy.assertNotNull(parent);
		// ==( PRE-CONDITION )======================================================================

		Composite result = new Composite(parent, SWT.NULL);
	
		// GridLayout
		GridLayout layout = new GridLayout();
		layout.numColumns = numColumns;
		result.setLayout(layout);
	
		// GridData
		GridData data = new GridData(GridData.FILL_BOTH);
		result.setLayoutData(data);
		
		return result;
	}
	
	/** Called to create a label with the given parent, labels it with the specified text.
	  *
	  * @param parent the parent composite.
	  * @param text the label's text. 
	  * @return the Label control.
	  */
	public static Label createLabel(Composite parent, String text)
	{
		// ==( PRE-CONDITION )======================================================================
		Policy.assertNotNull(parent);
		Policy.assertNotNull(text);
		// ==( PRE-CONDITION )======================================================================

		Label result = new Label(parent, SWT.NULL);
		result.setText(text);
		
		return result;
	}
}
